package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoginDemo {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            System.out.println("请输入用户名和密码");
            UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"登录","登录");
            String name = userInfo.getUsername();
            String pwd = userInfo.getPassword();
            String sql = "SELECT * FROM userinfo WHERE username = '"+name+"' AND password = '"+pwd+"'";
            ResultSet resultSet = statement.executeQuery(sql);
            boolean flag = resultSet.next();
            System.out.println(flag?"登录成功":"用户名或密码错误");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
